Opening external documents
How can I open external document such as Word, BMP file, multimedia file, or even
Windows/DOS application ?
By using ShellExecute API function which exists in ShellApi library.
Example:
- Drop an Edit box and a button to a form.
- Add ShellApi to Uses Clause.
- At button's OnClick event write:
ShellExecute(handle, 'open',
PChar(Edit1.Text), '', '', sw_Normal);
- Run the application and type a full-qualified file name to be opened and click
the button.
Notes:
- This function will open any file you have written on Edit box by the default windows
application depending on it's extension. For example if the file is 'c:\my documents\first.doc'
it will be opened by MS-Word; if MS-Word does not exists it will open it with Wordpad.
Bmp files will be opened with MS-Paint. Multimedia files will be opened by installed
multimedia applications such as Media Player.
- Open action can be replaced with other actions that available for that extension
such as Play, Print, Quick View, and others, all that depends on extension and application
that opens that extension. To view all extensions available actions run Windows
Explorer and right click on file with that extension to see it's actions that exists
at the top of pop-up menu.